# 逆向工程
import requests
from bs4 import BeautifulSoup

headers = {
    'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'
}
urls = ['https://www.pexels.com/search/book/?pag={}'.format(i) for i in range(1, 3)]
list = []
for url in urls:
    wb_data = requests.get(url, headers=headers)
    soup = BeautifulSoup(wb_data.text, 'lxml')
    imgs = soup.select('article > a > img')
    for img in imgs:
        photo = img.get('src')
        list.append(photo)
    path = 'D://pic/img'
    for item in list:
        data = requests.get(item, headers=headers)
        fp = open(path + item.split('?')[0][-10:], 'wb')
        fp.write(data.content)
        fp.close()
